﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Icms.Core.Model;
using Icms.Core.Repository;

namespace Icms.WebUI.Controllers
{
    public class CourtTypeIdAjaxDropdownController : Controller
    {
        private readonly IRepo<CourtType> r;

        public CourtTypeIdAjaxDropdownController(IRepo<CourtType> r)
        {
            this.r = r;
        }

        public ActionResult GetItems(Guid? key)
        {
            var list = new List<SelectListItem> { new SelectListItem { Text = "not selected", Value = "" } };

            list.AddRange(r.GetAll().Select(o => new SelectListItem
                                                     {
                                                         Text = o.Title,
                                                         Value = o.Id.ToString(),
                                                         Selected = o.Id == key
                                                     }));
            return Json(list);
        }
    }
}